package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Depot;
import cn.wolfcode.crm.domain.Supplier;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.serivce.IDepotService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("depot")
public class DepotController {
    @Autowired
    private IDepotService service;

    @RequestMapping("view")
    public String view() throws Exception {
        return "depot";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(QueryObject qo) throws Exception {
        PageResult query = service.query(qo);
        return query;
    }

    @ResponseBody
    @RequestMapping("delete")
    public JSONResult delete(Long id) throws Exception {
        try {
            service.deleteByPrimaryKey(id);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("操作失败!");
        }
    }

    @ResponseBody
    @RequestMapping("saveOrUpdate")
    public JSONResult saveOrUpdate(Depot depot) throws Exception {
        try {
            service.saveOrUpdate(depot);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("保存失败!");
        }
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<Depot> selectAll()throws Exception{
        return service.selectAll();
    }

}
